<?php

namespace App\Admin\Extensions\Form;

use Dcat\Admin\Form\Field;

class Category extends Field
{
    protected $view = 'form.category';

    /**
     * Field constructor.
     *
     * @param  string|array  $column
     * @param  array  $arguments
     */
    public function __construct($column, $arguments = [])
    {
        $this->column = $column;
        $this->label = $this->formatLabel($arguments);
        $this->attributes['placeholder'] = "请选择".$this->label;
        $this->checkStrategy();
        $this->isCheck();
        $this->multiple(false);
        $this->maxCount(false);
        $this->ruleText("请选择商品分类!");
        $this->callResolving();
    }


    /**
     * 设置placeholder
     */
    public function checkStrategy($checkStrategy = 'child'){
        $this->attributes['checkStrategy'] = $checkStrategy;
        return $this;
    }

    /**
     */
    public function isCheck($isCheck = false){
        $this->attributes['isCheck'] = $isCheck?1:0;
        return $this;
    }

    /**
     */
    public function maxCount($maxCount = true){
        $this->attributes['maxCount'] = $maxCount;
        return $this;
    }

    /**
     */
    public function multiple($multiple = true){
        $this->attributes['multiple'] = $multiple;
        return $this;
    }

    /**
     */
    public function ruleText($ruleText = ""){
        $this->attributes['ruleText'] = $ruleText;
        return $this;
    }

    public function render(){
        $this->addVariables(['extend'=>$this->attributes]);
        return parent::render();
    }
}
